package ldh.im.dto.codec.binery;

import io.netty.buffer.ByteBuf;
import ldh.im.dto.base.StatusResp;

public class StatusResultCodec extends ResultCodec<StatusResp> {

    @Override
    public void encode(StatusResp result, ByteBuf byteBuf) {
        super.encode(result, byteBuf);
        byteBuf.writeInt(result.getStatus());
    }

    @Override
    public void decode(StatusResp result, ByteBuf byteBuf) {
        super.decode(result, byteBuf);
        result.setStatus(byteBuf.readInt());
    }

    @Override
    public StatusResp create() {
        return new StatusResp();
    }

    @Override
    protected void checkEncode(StatusResp result) {
        super.checkEncode(result);
        if (result.getStatus() < 0L) {
            throw new RuntimeException("status值不正确, status=" + result.getStatus());
        }
    }
}